<?php

define('TABLE_ADDRESS', 'stubenadresse');
define('TABLE_EVENT', 'stubentermine');

define('CONST_DISTANCE', 10); 


function createLocationSelectWithDistance($latitude, $longitude, $where) {
	$circumferenceOfEarth = 6371;
	$deg2rad = pi() / 180;
	$latitudeInRad = $latitude * $deg2rad;
	$distanceSql = "ACOS( SIN( $latitudeInRad ) * SIN( $deg2rad * latitude ) + ".
			"COS( $latitudeInRad ) * COS( $deg2rad * latitude ) * COS( $deg2rad * (longitude - $longitude))) * $circumferenceOfEarth";
	$foodSql = "CASE zuordnung WHEN 7289 THEN 'restaurant' ELSE 'stuff' END";
	$typeSql = "CASE type WHEN 'base' THEN 'pension' WHEN 'branchen' THEN $foodSql ELSE 'stuff' END";
	return "SELECT id, title, null AS date, description, latitude, longitude, $typeSql AS type, street, zip, city, $distanceSql AS distance FROM ".TABLE_ADDRESS." $where\n".
		   "UNION\n".
		   "SELECT id, title, start AS date, description, latitude, longitude, 'date' AS type, street, zip, city, $distanceSql AS distance FROM ".TABLE_EVENT." $where\n";
}

function createEventSelectWithName($name, $federalState) {
	// TODO: use field for federal state
	return "SELECT DISTINCT title, description, latitude, longitude, street, zip, city, 'Sachsen' AS federalState FROM ".TABLE_EVENT." ".
		   "WHERE (title LIKE '%$name%' OR title SOUNDS LIKE '$name') "; //AND fld14 = $federalState";
}

?>